package com.ruoyi.web.controller.personnel;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.KeyPersonnelAdmin;
import com.ruoyi.system.domain.KeyPersonnelAdminType;
import com.ruoyi.system.service.KeyPersonnelAdminTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 两类重点人员(KeyPersonnelAdmin)表控制层
 *
 * @author makejava
 * @since 2022-11-18 09:31:26
 */
@RestController
@RequestMapping("keyPersonnelAdminType")
public class KeyPersonnelAdminTypeController extends BaseController {

    @Resource
    private KeyPersonnelAdminTypeService keyPersonnelAdminTypeService;

    /**
     * 分页查询
     *
     * @param keyPersonnelAdminType 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(KeyPersonnelAdminType keyPersonnelAdminType) {
        startPage();
        List<KeyPersonnelAdminType> riskOughtList = this.keyPersonnelAdminTypeService.queryByPage(keyPersonnelAdminType);
        return getDataTable(riskOughtList);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Integer id) {
        return AjaxResult.success(this.keyPersonnelAdminTypeService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param keyPersonnelAdminType 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    //@PreAuthorize("@ss.hasPermi('keyPersonnelAdminType:add')")
    public AjaxResult add(@RequestBody KeyPersonnelAdminType keyPersonnelAdminType) {
        return AjaxResult.success(this.keyPersonnelAdminTypeService.insert(keyPersonnelAdminType));
    }

    /**
     * 编辑数据
     *
     * @param keyPersonnelAdminType 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    //PreAuthorize("@ss.hasPermi('keyPersonnelAdminType:edit')")
    public AjaxResult edit(@RequestBody KeyPersonnelAdminType keyPersonnelAdminType) {
        return AjaxResult.success(this.keyPersonnelAdminTypeService.update(keyPersonnelAdminType));
    }

    /**
     * 删除数据
     *
     * @param keyPersonnelAdmin 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete")
    //@PreAuthorize("@ss.hasPermi('keyPersonnelAdminType:delete')")
    public AjaxResult deleteById(@Validated @RequestBody KeyPersonnelAdmin keyPersonnelAdmin) {
        return AjaxResult.success(this.keyPersonnelAdminTypeService.deleteById(keyPersonnelAdmin.getId()));
    }

}

